package com.app.controller;


import com.alibaba.fastjson.JSONObject;
import com.app.model.FwLcwh;
import com.app.service.IFwLcwhService;
import com.app.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 房屋楼层调差 前端控制器
 * </p>
 *
 * @author yoominic
 * @since 2025-02-27
 */
@Api(tags = "房屋楼层调差")
@RestController
@RequestMapping("/fwLcwh")
public class FwLcwhController {

    @Autowired
    private IFwLcwhService fwLcwhService;

    @ApiOperation(value = "获取房屋楼层调差列表", notes = "获取房屋楼层调差列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "每页条数", required = true, dataType = "Integer")
    })
    @GetMapping("/adminGetFwlcList")
    private Result adminGetFwlcList(Integer page, Integer limit){
        Page<FwLcwh> pageParam = new Page<>(page, limit);

        QueryWrapper<FwLcwh> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("lc_value");
        Page<FwLcwh> pageResult = fwLcwhService.page(pageParam, queryWrapper);

        JSONObject result = new JSONObject();
        result.put("total", pageResult.getTotal());
        result.put("items", pageResult.getRecords());
        return Result.success(pageResult);
    }

    @ApiOperation(value = "保存房屋楼层调差", notes = "保存房屋楼层调差")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fwLcwh", value = "房屋楼层调差对象", required = true, dataType = "FwLcwh")
    })
    @PostMapping("/adminSaveFwlc")
    public Result adminSaveFwlc(@RequestBody FwLcwh fwLcwh){
        if (fwLcwh.getId() == null) {
            fwLcwhService.save(fwLcwh);
        } else {
            fwLcwhService.updateById(fwLcwh);
        }
        return Result.success("操作成功！");
    }

}

